<div class="modal fade" id="cart-dlg">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <form id="cart-form" action="{{route('sys.cart.add')}}" method="post">
                {{csrf_field()}}
                <input type="hidden" name="no" id="add-no" value=""/>
                <div class="modal-header">
                    <h4 class="modal-title">加入购物车</h4>
                </div>
                <div class="modal-body">
                    <div class="row input-row">
                        <div class="col-xs-offset-1">
                            <label class="col-xs-12 title">
                                购买数量 - Purchase quantity
                            </label>
                        </div>
                        <div class="col-md-6 col-xs-12 col-xs-offset-1">
                            <div class="input-group">
                            <span class="input-group-addon">
                                <i class="iconfont icon-bixuan-copy font-red"></i>
                            </span>
                                <input id="buy-num" name="buy-num" type="number"
                                       class="form-control">
                            </div>
                        </div>
                        <div class="col-md-5 col-xs-12">
                            <label class="label-intro" id="unit-intro">
                            </label>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <a href="#" id="del-pro" class="btn btn-default">取消</a>
                    <button type="submit" class="btn btn-primary">加入购物车</button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script type="text/javascript">
    var goCart = false;

    function cartDlg(no, unit, go) {
        $("#add-no").val(no);
        $("#buy-num").val(unit);
        $("#unit-intro").html("购买数量必须为 " + unit + " 的倍数！");
        $("#detail-dlg").modal('hide');
        $("#cart-dlg").modal();
        goCart = go;

        if (go) {
            $("#del-pro").html("删除商品");
            $("#del-pro").attr("href", "{{route('sys.cart.del')}}/" + no);
        }
    }
    $("#cart-form").validate({
        rules: {
            "buy-num": "required",
            "no": "required",
        }, errorPlacement: function (error, element) {
            $(element).closest(".input-row").find(".label-intro").html(error);
        },
        submitHandler: function (form) {
            $(form).ajaxSubmit({
                dataType: "json",
                type: "post",
                success: function (data) {
                    if (data.code == 0) {
                        toastr["success"](data.msg);
                        $('#cart-dlg').modal('hide');
                        if (goCart) {
                            window.location = "{{route('sys.carts')}}";
                        }
                    } else {
                        toastr["error"](data.msg);
                    }
                }
            });
        }
    });
</script>